﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{

    [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.business})]
    public class HistorysController:BaseController  
    {
        private readonly IHistorysServer _historysServer;

        public HistorysController(IHistorysServer historysServer)
        {
            _historysServer = historysServer;
        }

        /// <summary>
        /// 添加历史记录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add(RequestCreateHistorysDto dto){
            return Send(await _historysServer.Add(dto,_business.BId));
        }
        /// <summary>
        /// 删除历史记录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete(RequestIdHistorysDto dto){
            return Send(await _historysServer.Delete(dto,_business.BId));
        }
        /// <summary>
        /// 清除所有历史记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ClearAll(){
            return Send(await _historysServer.ClearAll(_business.BId));
        }
        /// <summary>
        /// 历史记录分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Pagination(int page, int limit){
            return Send(await _historysServer.Pagination(page,limit,_business.BId));
        }
    }
}
